package jmine.tec.publisher;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import jmine.tec.subscription.SubscriptionSettings;
import jmine.tec.subscription.impl.AbstractPublisher;

public class FastPublisher extends AbstractPublisher<SimplePublication> {

    public FastPublisher() {
        super(SimplePublication.class);
    }

    @Override
    public void evict(SubscriptionSettings settings) {
    }

    public String identification() {
        return "fastPublisher";
    }

    public SimplePublication newPublication(SubscriptionSettings settings) {
        return new SimplePublication("new");
    }

    public void publishAndMeasure(int number) {
        System.out.println("sending: " + number + "msgs");
        final SimplePublication p = new SimplePublication("now");
        final SubscriptionSettings newSubscriptionSettings = this.newSubscriptionSettings(new HashMap<String, Object>());
        long s0 = System.nanoTime();
        for (int i = 0; i < number; i++) {
            this.publish(newSubscriptionSettings, p);
        }
        final long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - s0);
        double msgsPerMs = ((double) number) / millis;
        System.out.println("total time: " + millis);
        System.out.println("msgs / ms: " + msgsPerMs);
    }

    public Map<String, Class<?>> subscriptionSettingsParameters() {
        return new HashMap<String, Class<?>>();
    }

}
